var t = require("../../../@babel/runtime/helpers/defineProperty"), e = require("../common").getProjectNameLang, o = getApp(), n = o.getNetAddresss("plugin.store-projects.frontend.project-service.get-service-info"), s = o.getNetAddresss("plugin.store-projects.frontend.project-service.create"), r = o.getNetAddresss("plugin.store-projects.frontend.project-service.get-detail");

Page({
    data: {
        projectOrderId: null,
        project: null,
        used_count: 1
    },
    onLoad: function(t) {
        var o = null;
        t.scene ? o = this.sceneDecode(t.scene).service_id : t.id && (o = t.id);
        if (!o) return wx.showToast({
            title: e() + "不存在",
            icon: "none"
        }), void wx.navigateBack({
            delta: 1
        });
        this.setData({
            projectOrderId: o
        }), this.getProject();
    },
    sceneDecode: function(t) {
        var e = (t = decodeURIComponent(t)).split("&"), o = {};
        return e.forEach(function(t, e) {
            var n = t.split("=")[0], s = t.split("=")[1];
            o[n] = s;
        }), o;
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.getProject();
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    inputElChanged: function(t) {
        var e = t.detail;
        this.setData({
            used_count: e.value
        });
    },
    getProject: function() {
        var t = this;
        wx.showLoading(), o._getNetWork({
            url: n,
            data: {
                id: this.data.projectOrderId
            },
            success: function(e) {
                var o = e.data, n = o.data, s = o.result, r = o.msg;
                wx.hideLoading(), wx.stopPullDownRefresh(), 0 !== s ? t.setData({
                    project: n
                }) : wx.showToast({
                    title: r,
                    icon: "none"
                });
            }
        });
    },
    confirmWriteOff: function() {
        var e = this;
        this.data.project.rest_count <= 0 ? wx.showToast({
            title: "剩余次数不足，请核对后核销",
            icon: "none"
        }) : this.data.used_count ? (wx.showLoading(), o._getNetWork({
            url: s,
            data: {
                id: this.data.projectOrderId,
                used_count: this.data.used_count
            },
            success: function(n) {
                var s = n.data, i = s.data, a = s.result, c = s.msg;
                wx.hideLoading(), 0 !== a ? (wx.showToast({
                    title: "核销成功",
                    icon: "none"
                }), o._getNetWork({
                    url: r,
                    data: {
                        id: i.id
                    },
                    success: function(o) {
                        var n, s = o.data, r = s.data, i = s.result, a = s.msg;
                        0 !== i ? e.setData((t(n = {}, "project.rest_count", r.total_rest_count), t(n, "project.used_count", r.total_use_count), 
                        t(n, "project.end_time", r.end_time), n)) : wx.showToast({
                            title: a,
                            icon: "none"
                        });
                    }
                })) : wx.showToast({
                    title: c,
                    icon: "none"
                });
            }
        })) : wx.showToast({
            title: "请输入正确的核销次数",
            icon: "none"
        });
    }
});